import Vue from 'vue'
import * as Util from '../../components/Util'

let PrintService = {
  install (Vue, options) {
    // 给vue增添对话框显示方法
    Vue.PrintService = Vue.prototype.$PrintService = PrintService
  },

  // 打印发票
  modifyBillNumber (model, row) {
    let data = {}
    if (row.f_bill_type === '其他收费') {
      data = {
        billcoll: {
          id: model.f_billcoll_id,
          f_bill_id: model.f_bill_id + 1
        },
        detail: {
          f_billcoll_id: model.f_billcoll_id,
          f_bill_id: model.f_bill_id,
          f_userinfo_id: row.f_userinfo_id,
          f_user_id: row.f_user_id,
          f_user_name: row.f_user_name,
          f_billdetail_id: row.id,
          f_card_id: row.f_card_id,
          f_bill_type: row.f_bill_type,
          f_bill_state: '已用',
          f_total_money: (row.f_unitprice - 0) * (row.f_number - 0),
          f_paid_money: row.f_collection - 0,
          f_operator: Util.f.name,
          f_filiale: Util.f.f_fengongsi,
          f_outlets: Util.f.f_parentname,
          f_bill_style: row.f_charge_type[0]
        },
        type: '打印发票'
      }
    } else if (row.f_bill_type === '换新表') {
      data = {
        billcoll: {
          id: model.f_billcoll_id,
          f_bill_id: model.f_bill_id + 1
        },
        detail: {
          f_billcoll_id: model.f_billcoll_id,
          f_bill_id: model.f_bill_id,
          f_userinfo_id: row.f_userinfo_id,
          f_user_id: row.f_user_id,
          f_user_name: row.f_user_name,
          f_billdetail_id: row.id,
          f_card_id: row.f_card_id,
          f_bill_type: row.f_bill_type,
          f_bill_state: '已用',
          f_total_money: row.f_changemeter_fee - 0,
          f_paid_money: row.f_changemeter_fee - 0,
          f_operator: Util.f.name,
          f_filiale: Util.f.f_fengongsi,
          f_outlets: Util.f.f_parentname,
          f_bill_style: row.f_charge_type[0]
        },
        type: '打印发票'
      }
    } else {
      data = {
        billcoll: {
          id: model.f_billcoll_id,
          f_bill_id: model.f_bill_id + 1
        },
        detail: {
          f_billcoll_id: model.f_billcoll_id,
          f_bill_id: model.f_bill_id,
          f_userinfo_id: row.f_userinfo_id,
          f_user_id: row.f_user_id,
          f_user_name: row.f_user_name,
          f_billdetail_id: row.id,
          f_card_id: row.f_card_id,
          f_bill_type: row.f_bill_type,
          f_bill_state: '已用',
          f_total_money: row.f_preamount ? row.f_preamount - 0 : row.logicmodel.f_preamount - 0,
          f_paid_money: row.f_collection ? row.f_collection - 0 : row.logicmodel.f_collection - 0,
          f_operator: Util.f.name,
          f_filiale: Util.f.f_fengongsi,
          f_outlets: Util.f.f_parentname,
          f_bill_style: row.f_bill_style
        },
        type: '打印发票'
      }
    }
    console.log('data', JSON.stringify(data))
    return Vue.resetpost('rs/logic/printBill', {data: data}, {resolveMsg: '打印发票成功', rejectMsg: '打印发票失败'})
  },
  ReissueBill (model, row, type) {
    if (type === 'new') {
      let data = {
        billcoll: {
          id: model.f_billcoll_id,
          f_bill_id: model.f_bill_id + 1
        },
        detail: {
          f_billcoll_id: model.f_billcoll_id,
          f_bill_id: model.f_bill_id,
          f_billdetail_id: row.id,
          f_bill_state: '已用',
          f_bill_type: `${row.type}(补打)`,
          f_operator: Util.f.name,
          f_filiale: Util.f.f_fengongsi,
          f_outlets: Util.f.f_parentname,
          f_cause: model.f_cause
        },
        type: '票据补打'
      }
      return Vue.resetpost('rs/logic/printBill', {data: data}, {resolveMsg: '补打票据成功', rejectMsg: '补打票据失败'})
    } else if (type === 'old') {
      let data = {
        detail: {
          f_billcoll_id: model.f_billcoll_id,
          f_bill_id: model.f_bill_id,
          f_billdetail_id: row.id,
          f_bill_state: '已用',
          f_bill_type: `${row.type}(补打)`,
          f_operator: Util.f.name,
          f_filiale: Util.f.f_fengongsi,
          f_outlets: Util.f.f_parentname,
          f_cause: model.f_cause
        },
        type: '票据补打'
      }
      return Vue.resetpost('rs/logic/printBill', {data: data}, {resolveMsg: '补打票据成功', rejectMsg: '补打票据失败'})
    }
  }
}

export default PrintService
